package com.woniuxy.java106crm.controller;

import com.woniuxy.java106crm.annotation.RequireMethod;
import com.woniuxy.java106crm.entity.CustomerTrade;
import com.woniuxy.java106crm.request.ResponseResult;
import com.woniuxy.java106crm.service.CustomerTradeService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(tags = "客户交往记录管理模块API文档")
@Slf4j
@RestController
@RequestMapping("/customertrade")
public class CustomerTradeController {

    @Resource
    private CustomerTradeService customerTradeService;

    @PreAuthorize("hasAuthority('客户信息管理')")
    @RequireMethod("查询客户交往记录")
    @GetMapping("/findAllByCid/{cid}")
    public ResponseResult<List<CustomerTrade>> findAllByCid(@PathVariable("cid") String cid){
        return new ResponseResult<>(ResponseResult.OK,customerTradeService.findAllByCid(cid));
    }

    @PreAuthorize("hasAuthority('客户信息管理')")
    @RequireMethod("删除客户交往记录")
    @DeleteMapping("/deleteById/{id}")
    public ResponseResult<Boolean> deleteById(@PathVariable("id") String id){
        log.debug("{}",id);
        return new ResponseResult<>(ResponseResult.OK,customerTradeService.deleteById(id));
    }

    @PreAuthorize("hasAuthority('客户信息管理')")
    @RequireMethod("新增客户交往记录")
    @PostMapping("/addTrade")
    public ResponseResult<Boolean> addTrade(@RequestBody CustomerTrade customerTrade){
//        log.debug(customerTrade.toString());
        return new ResponseResult<>(ResponseResult.OK,customerTradeService.addTrade(customerTrade));
    }

    @PreAuthorize("hasAuthority('客户信息管理')")
    @RequireMethod("编辑客户交往记录")
    @PostMapping("/updateTrade")
    public ResponseResult<Boolean> updateTrade(@RequestBody CustomerTrade customerTrade){
//        log.debug(customerTrade.toString());
        return new ResponseResult<>(ResponseResult.OK,customerTradeService.updateTrade(customerTrade));
    }

    @PreAuthorize("hasAuthority('客户信息管理')")
    @RequireMethod("批量删除客户交往记录")
    @DeleteMapping("/batchedDelByIds/{ids}")
    public ResponseResult<Boolean> batchedDelByIdsv(@PathVariable("ids")String ids){
        log.debug("{}",ids);
        customerTradeService.batchedDelByIdsv(ids);
        return new ResponseResult<>(ResponseResult.OK,true);
    }
}
